def myAtoi(s: str) -> int:
    res = ''
    for i, c in enumerate(s):
        if res == '':
            if c == '-':
                res += c
            elif c == '+':
                res += c
            elif '0' <= c <= '9':
                res += c
            elif c == ' ':
                continue
            else:
                return 0
        else:
            if '0' <= c <= '9':
                res += c
            else:
                break

    if res == '' or res == '-' or res == '+':
        return 0
    res = int(res)

    if 2**31-1 < res:
        return 2**31-1

    if res < -2**31:
        return -2**31
    return res


print(myAtoi('91283472332'))
